﻿using System;
using ContainerHost.ServiceModel;

namespace ContainerHost.Unity
{
    /// <summary>
    /// UnityServiceHost Factory
    /// </summary>
    public class UnityServiceHostFactory : System.ServiceModel.Activation.ServiceHostFactory
    {
        /// <summary>
        /// Provides an instance of the UnityServiceHost
        /// </summary>
        /// <param name="serviceType"></param>
        /// <param name="baseAddresses"></param>
        /// <returns>A ContainerServiceHost initialized with a Unity Container.</returns>
        protected override System.ServiceModel.ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
        {
            ContainerServiceHost serviceHost = new ContainerServiceHost(serviceType, baseAddresses);
            UnityContainerFacade container = new UnityContainerFacade();
            serviceHost.Container = container;

            return serviceHost;
        }
    }
}
